﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Medical.Business;
using Medical.Entity;

/// <summary>
/// Until 的摘要说明
/// </summary>
public class Until
{

    public static ConfigInfo config = null;

    public static ConfigInfo GetConfig()
    {
        if (config == null)
            config = new BisConfigInfo().Get(1);
        return config;
    }

    public static DataTable WebBanner = null;

    public static DataTable GetWebBanner()
    {
        if (WebBanner == null)
            WebBanner = new BisBanner().GetList(AdverTypeEnum.Banner);
        return WebBanner;
    }

    public static DataTable SEO = null;

    public static DataTable GetSEO()
    {
        if (SEO == null)
            SEO = new BisSeo().GetList();
        return SEO;
    }

    /// <summary>
    /// 注册提示脚本
    /// </summary>
    /// <param name="strAlert">提示内容</param>
    /// <returns></returns>
    public static void Alert(string strAlert)
    {
        Page p = (Page)System.Web.HttpContext.Current.Handler;
        p.ClientScript.RegisterStartupScript(p.GetType(), "", "alert('" + strAlert + "');", true);
    }

    /// <summary>
    /// 注册提示脚本
    /// </summary>
    /// <param name="strAlert">提示内容</param>
    /// <param name="strURL">返回页</param>
    /// <returns></returns>
    public static void Alert(string strAlert, string strURL)
    {
        Page p = (Page)System.Web.HttpContext.Current.Handler;
        p.ClientScript.RegisterStartupScript(p.GetType(), "", "alert('" + strAlert + "');location.replace('" + strURL + "');", true);
    }

    /// <summary>
    /// 注册提示脚本
    /// </summary>
    /// <param name="strAlert">提示内容</param>
    /// <param name="strURL">返回页</param>
    /// <returns></returns>
    public static void AlertJS(string strAlert, string strJS)
    {
        Page p = (Page)System.Web.HttpContext.Current.Handler;
        p.ClientScript.RegisterStartupScript(p.GetType(), "", "alert('" + strAlert + "');"+strJS, true);
    }
    /// <summary>
    /// 注册提示脚本
    /// </summary>
    /// <param name="strAlert">提示内容</param>
    /// <param name="strURL">返回页</param>
    /// <returns></returns>
    public static void AlertBefaultJS(string strAlert, string strJS)
    {
        Page p = (Page)System.Web.HttpContext.Current.Handler;
        p.ClientScript.RegisterStartupScript(p.GetType(), "", strJS+"alert('" + strAlert + "');", true);
    }

    /// <summary>
    /// 验证文件类型
    /// </summary>
    /// <param name="nType">类型(0:图片,1:文档)</param>
    /// <param name="extension">文件后缀</param>
    /// <returns></returns>
    public static bool CheckFileType(int nType, string strExtension)
    {
        string[] filetype;
        if (nType == 0)
        {
            //图片
            filetype = new string[] { ".jpg", ".png", ".gif", ".jpeg", ".bmp" };
        }
        else
        {
            //文档
            filetype = new string[] { ".doc", ".rar", ".zip", ".txt", ".xls" };
        }
        foreach (string strType in filetype)
        {
            if (strType == strExtension)
            {
                return true;
            }
        }
        return false;
    }

    /// <summary>
    /// 删除文件
    /// </summary>
    /// <param name="strFilePlace">文字路径</param>
    /// <returns></returns>
    public static bool DeleteFile(string strFilePlace)
    {
        try
        {
            if (File.Exists(strFilePlace))
            {
                File.Delete(strFilePlace);
            }
        }
        catch
        {
            return false;
        }
        return true;
    }

    /// <summary>
    /// 获取文章类型名称
    /// </summary>
    /// <param name="eType"></param>
    /// <returns></returns>
    public static string GetArticleName(ArticelTypeEnum eType)
    {
        switch (eType)
        {
            case ArticelTypeEnum.About:
                return "关于我们";
            case ArticelTypeEnum.Disease:
                return "疾病";
            case ArticelTypeEnum.News:
                return "新闻";
            case ArticelTypeEnum.Subject:
                return "热点专题";
            case ArticelTypeEnum.Expert:
                return "专家团队";
            case ArticelTypeEnum.Equipment:
                return "设备";
            case ArticelTypeEnum.Technology:
                return "前沿技术";
            case ArticelTypeEnum.Case:
                return "成功案例";
            case ArticelTypeEnum.Guide:
                return "就医指南";
            case ArticelTypeEnum.Health:
                return "症状";
            case ArticelTypeEnum.FeedBack:
                return "专家答疑";
        }
        return "";
    }


    /// <summary>
    /// 获取广告类型名称
    /// </summary>
    /// <param name="eType"></param>
    /// <returns></returns>
    public static string GetAdverName(AdverTypeEnum eType)
    {
        switch (eType)
        {
            case AdverTypeEnum.Banner:
                return "头部广告栏";
            case AdverTypeEnum.HomeAdv:
                return "首页广告栏";
            case AdverTypeEnum.Honor:
                return "首页荣誉";
            case AdverTypeEnum.Subject:
                return "专题广告栏";
            case AdverTypeEnum.Environment:
                return "医院环境广告栏";
            case AdverTypeEnum.Disease:
                return "疾病幻灯片";
            case AdverTypeEnum.FontDisease:
                return "疾病技术广告栏";
            case AdverTypeEnum.Health:
                return "症状广告栏";
            case AdverTypeEnum.Health1:
                return "症状广告栏";
        }
        return "";
    }

    /// <summary>
    /// 获取页面路径
    /// </summary>
    /// <param name="oPSortUrl"></param>
    /// <param name="oSortUrl"></param>
    /// <param name="oID"></param>
    public static string GetUrlName(object oPSortUrl,object oSortUrl,object oID){
        string strUrl=string.Empty;
        if(!string.IsNullOrEmpty(oPSortUrl.ToString()))
            strUrl+="/"+oPSortUrl.ToString();
         if(!string.IsNullOrEmpty(oSortUrl.ToString()))
            strUrl+="/"+oSortUrl.ToString();
        return strUrl+"/"+oID.ToString()+".html";
    }

    /// <summary>
    /// 获取页面路径
    /// </summary>
    /// <param name="oPSortUrl"></param>
    /// <param name="oSortUrl"></param>
    /// <param name="oID"></param>
    public static string GetUrlName(object oArticleType, object oPSortUrl, object oSortUrl, object oID)
    {
        if (Convert.ToInt32(oArticleType) == 0)
        {
            string strUrl = string.Empty;
            if (!string.IsNullOrEmpty(oPSortUrl.ToString()))
                strUrl += "/" + oPSortUrl.ToString();
            if (!string.IsNullOrEmpty(oSortUrl.ToString()))
                strUrl += "/" + oSortUrl.ToString();
            return strUrl + "/" + oID.ToString() + ".html";
        }
        else
        {
            return "/faq/" + oSortUrl.ToString() + "/" + oID.ToString() + ".html";
        }
    }

    /// <summary>
    /// 创建新的表
    /// </summary>
    /// <returns></returns>
    public static DataTable CreateNewDT(DataTable dt,DataRow[] drList)
    {
        DataTable dtNew = dt.Clone();
        foreach (DataRow dr in drList)
        {
            DataRow drTem = dtNew.NewRow();
            foreach (DataColumn column in dt.Columns)
            {
                drTem[column.ColumnName] = dr[column.ColumnName];
            }
            dtNew.Rows.Add(drTem);
        }
        return dtNew;
    }

}

/// <summary>
/// 权限记录表
/// </summary>
public class AdminFEATURE
{
    /// <summary>
    /// 分类管理
    /// </summary>
    public static readonly long Sort = 0x4000;
   
    /// <summary>
    /// 文章管理
    /// </summary>
    public static readonly long Article = 0x17FE;

    /// <summary>
    /// 新闻列表
    /// </summary>
    public static readonly long News = 0x8;

    /// <summary>
    /// 疾病管理
    /// </summary>
    public static readonly long Disease = 0x2;

    /// <summary>
    /// 专题管理
    /// </summary>
    public static readonly long Subject = 0x4;

    /// <summary>
    /// 专家团队列表
    /// </summary>
    public static readonly long Expert = 0x10;

    /// <summary>
    /// 尖端设备列表
    /// </summary>
    public static readonly long Equipment = 0x20;

    /// <summary>
    /// 领先技术列表
    /// </summary>
    public static readonly long Technology = 0x40;

    /// <summary>
    /// 典型病例列表
    /// </summary>
    public static readonly long Case = 0x80;

    /// <summary>
    /// 就医指南列表
    /// </summary>
    public static readonly long Guide = 0x100;

    /// <summary>
    /// 健康讲堂列表
    /// </summary>
    public static readonly long Health = 0x200;

    /// <summary>
    /// 关于我们列表
    /// </summary>
    public static readonly long About = 0x400;

    /// <summary>
    /// 专家答疑管理
    /// </summary>
    public static readonly long FeedBack = 0x1000;

    /// <summary>
    /// 广告栏管理
    /// </summary>
    public static readonly long Adver = 0x800;

    /// <summary>
    /// 站点管理
    /// </summary>
    public static readonly long Site = 0x2000;

}

